#include "../BSP/pwm.h"

#ifdef DEBUG
TIM_HandleTypeDef *last_tim = NULL;
uint32_t last_channel = 0;
#else
static TIM_HandleTypeDef *last_tim = NULL;
static uint32_t last_channel = 0;
#endif

void HAL_TIM_PWM_PulseFinishedCallback(TIM_HandleTypeDef *htim) {
  HAL_TIM_PWM_Stop_DMA(last_tim, last_channel);
}

uint8_t BSP_PWM_Start(TIM_HandleTypeDef *htim, uint32_t Channel,
                      uint32_t *pData, uint16_t Length) {
  last_tim = htim;
  last_channel = Channel;
  return HAL_TIM_PWM_Start_DMA(htim, Channel, pData, Length);
}

uint8_t BSP_PWM_Stop(TIM_HandleTypeDef *htim, uint32_t Channel) {
  return HAL_TIM_PWM_Stop_DMA(htim, Channel);
}
